import { Context  } from "egg"
import { appendFileSync } from 'fs'
export default (options )=> {
    return async (ctx:Context,next:()=>Promise<any>)=> {
        const startTime = Date.now()
        const DataTime = new Date().toLocaleString()
        await next()
        const ms = Date.now() - startTime
        const responseDatelog = `${DataTime}--${ctx.method} -- ${ctx.url} -- ${ctx.status} -- ${ms}ms`
        if(options.methods.includes(ctx.method))  {
            appendFileSync('./log.txt',responseDatelog + '\n')
        }
       
    }
}